<include file="Public/min-header" />
<script type="text/javascript">
    window.UEDITOR_Admin_URL = "__ROOT__/Public/plugins/Ueditor/";
    var URL_upload = "{$URL_upload}";
    var URL_fileUp = "{$URL_fileUp}";
    var URL_scrawlUp = "{$URL_scrawlUp}";
    var URL_getRemoteImage = "{$URL_getRemoteImage}";
    var URL_imageManager = "{$URL_imageManager}";
    var URL_imageUp = "{$URL_imageUp}";
    var URL_getMovie = "{$URL_getMovie}";
    var URL_home = "{$URL_home}";
</script>
<load href="__ROOT__/Public/plugins/Ueditor/ueditor.config.js" />
<load href="__ROOT__/Public/plugins/Ueditor/ueditor.all.js" />
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<div class="wrapper">
    <include file="Public/breadcrumb" />
    <section class="content ">
        <div class="container-fluid">
            <div class="pull-right">
                <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i> 编辑订单促销活动  </h3>
                </div>
                <div class="panel-body ">
                    <form method="post" id="promotion" action="{:U('Admin/Promotion/actionOrderSave')}">

                        <div class="tab-content col-md-10">
                            <div class="tab-pane active" id="tab_tongyong">
                                <table class="table table-bordered">
                                    <tbody>
                                        <tr>
                                            <td class="col-sm-2 text-right">促销活动名称：</td>
                                            <td class="col-sm-8">
                                                <input type="text" class="form-control" name="name" id="name" value="{$info.name}">
                                                <span id="err_attr_name" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="col-sm-2 text-right">促销活动类型：</td>
                                            <td class="col-xs-8">
                                                <select id="prom_type" name="type" class="form-control" style="witdh:150px;">
                                                    <option value="0" <if condition="$info[type] eq 0">selected</if>>满额打折</option>
                                                    <option value="1" <if condition="$info[type] eq 1">selected</if>>满额优惠金额</option>
                                                    <option value="2" <if condition="$info[type] eq 2">selected</if>>满额送积分</option>
                                                    <option value="3" <if condition="$info[type] eq 3">selected</if>>满额送优惠券</option>
                                                <option value="4" <if condition="$info[type] eq 4">selected</if>>满额免运费</option>
                                                </select>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="col-sm-2 text-right">需要满足的金额：</td>
                                            <td class="col-sm-8">
                                                <input type="text" class="form-control" name="money" id="money" value="{$info.money}" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onkeyup="this.value = this.value.replace(/[^\d.]/g, '')" />
                                                <span id="err_attr_name" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr id="expression">
                                            <td class="col-sm-2 text-right">折扣：</td>
                                            <td>
                                                <input type="text" name="expression" value="{$info.expression}" class="" style="witdh:150px" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onkeyup="this.value = this.value.replace(/[^\d.]/g, '')" />
                                                <label>% 折扣值(1-100 如果打9折，请输入90)</label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">开始时间：</td>
                                            <td>
                                                <input type="text" class="form-control" id="start_time" name="start_time" value="{$info.start_time}">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">结束时间：</td>
                                            <td>
                                                <input type="text" class="form-control" id="end_time" name="end_time" value="{$info.end_time}">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">适合用户范围：</td>
                                            <td>
                                    <foreach name="level" item="vo">
                                        <input type="checkbox" <if condition="in_array($vo['level_id'],$info['group'])">checked</if> name="group[]" value="{$vo.level_id}">{$vo.level_name} &nbsp;&nbsp;&nbsp;&nbsp;
                                    </foreach>
                                    </td>
                                    </tr>
                                    <tr>
                                        <td class="col-sm-2 text-right">活动描述：</td>
                                        <td class="col-sm-8">
                                            <textarea class="span12 ckeditor" id="post_content" name="description" title="">
                                                    {$info.description}
                                            </textarea>
                                        </td>
                                    </tr>
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <td>
                                                <input class="btn btn-default" type="reset" value="重置">
                                                <input type="hidden" name="id" value="{$info.id}">
                                            </td>
                                            <td class="text-right">
                                                <input class="btn btn-primary" type="button" onclick="adsubmit()" value="保存">
                                            </td>
                                        </tr>
                                    </tfoot>
                                </table>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
</div>
<script>
    var editor;
    $(function () {
        //具体参数配置在  editor_config.js 中
        var options = {
            zIndex: 999,
            initialFrameWidth: "100%", //初化宽度
            initialFrameHeight: 350, //初化高度
            focus: false, //初始化时，是否让编辑器获得焦点true或false
            maximumWords: 99999,
            removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign', //允许的最大字符数 'fullscreen',
            pasteplain: true,
            autoHeightEnabled: true,
            autotypeset: {
                mergeEmptyline: true, //合并空行
                removeClass: true, //去掉冗余的class
                removeEmptyline: false, //去掉空行
                textAlign: "left", //段落的排版方式，可以是 left,right,center,justify 去掉这个属性表示不执行排版
                imageBlockLine: 'center', //图片的浮动方式，独占一行剧中,左右浮动，默认: center,left,right,none 去掉这个属性表示不执行排版
                pasteFilter: false, //根据规则过滤没事粘贴进来的内容
                clearFontSize: false, //去掉所有的内嵌字号，使用编辑器默认的字号
                clearFontFamily: false, //去掉所有的内嵌字体，使用编辑器默认的字体
                removeEmptyNode: false, //去掉空节点
                removeTagNames: {
                    "font": 1
                },
                indent: false, // 行首缩进
                indentValue: '0em' //行首缩进的大小
            },
            toolbars: [
                ['fullscreen', 'source', '|', 'undo', 'redo', '|', 'bold', 'italic', 'underline', 'fontborder',
                    'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset',
                    'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist',
                    'insertunorderedlist', 'selectall', 'cleardoc', '|', 'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                    'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|', 'directionalityltr', 'directionalityrtl',
                    'indent', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase',
                    'tolowercase', '|', 'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter',
                    '|', 'insertimage', 'emotion', 'insertvideo', 'attachment', 'map', 'gmap', 'insertframe',
                    'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|', 'horizontal', 'date', 'time',
                    'spechars', 'wordimage', '|', 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow',
                    'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows',
                    'splittocols', '|', 'print', 'preview', 'searchreplace'
                ]
            ]
        };
        editor = new UE.ui.Editor(options);
        editor.render("post_content");
    });

    function adsubmit() {
        if ($('#name').val() == '') {
            layer.msg('活动名称不能为空');
            return false;
        }
        if ($('input[name=expression]').val() == '') {
            layer.msg('优惠不能为空');
            return false;
        }
        $('#promotion').submit();
    }


    function call_back(table_html) {
        layer.closeAll('iframe');
        $('#goodsList').append(table_html);
    }


    $("#prom_type").on("change", function () {
        var type = parseInt($("#prom_type").val());
        var expression = '';
        switch (type) {

            case 0:
            {
                expression = '<td class="text-right"><b class="red">*</b>折扣：</td> <td> <input name="expression" type="text" class="small"  pattern="([1-9]\\d?|100)" value=""> <label>% 折扣值(1-100 如果打9折，请输入90)</label> </td>';
                break;
            }
            case 1:
            {
                expression = '<td class="text-right"><b class="red">*</b>优惠金额：</td> <td> <input name="expression" type="text" class="small"  pattern="float" value=""> <label>立减金额（元）</label> </td>';
                break;
            }
            case 2:
            {
                expression = '<td class="text-right"><b class="red">*</b>积分：</td> <td> <input name="expression" type="text" class="small"  pattern="int" value=""> <label>订单送积分额度!</label> </td>';
                break;
            }
            case 3:
            {
                expression = '<td class="text-right"><b class="red">*</b>优惠券：</td> <td><select name="expression"><volist name="couponList" id="v"><option value="{$v.id}" <if condition="$v[id] eq $info[expression]">selected</if>>{$v.name}</option></volist></select></td>';
                break;
            }
            case 4:
            {
                expression = '';
                break;
            }
        }
        $("#expression").html(expression);
    });

    $(document).ready(function () {
        $("#prom_type").trigger('change');
        $('input[name=expression]').val("{$info.expression}");

        $('#start_time').daterangepicker({
            format: "YYYY-MM-DD HH:mm:ss",
            singleDatePicker: true,
            showDropdowns: true,
            minDate: '{$min_date}',
            maxDate: '2030-01-01',
            startDate: '{$min_date}',
            timePicker: true, //是否显示小时和分钟  
            timePickerIncrement: 1, //time选择递增数
            timePicker12Hour: false, //是否使用12小时制来显示时间   
            locale: {
                applyLabel: '确定',
                cancelLabel: '取消',
                fromLabel: '起始时间',
                toLabel: '结束时间',
                customRangeLabel: '自定义',
                daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
                monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
                firstDay: 1
            }
        });

        $('#end_time').daterangepicker({
            format: "YYYY-MM-DD HH:mm:ss",
            singleDatePicker: true,
            showDropdowns: true,
            minDate: '{$min_date}',
            maxDate: '2030-01-01',
            startDate: '{$min_date}',
            timePicker: true, //是否显示小时和分钟  
            timePickerIncrement: 1, //time选择递增数
            timePicker12Hour: false, //是否使用12小时制来显示时间     
            locale: {
                applyLabel: '确定',
                cancelLabel: '取消',
                fromLabel: '起始时间',
                toLabel: '结束时间',
                customRangeLabel: '自定义',
                daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
                monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
                firstDay: 1
            }
        });
    })
</script>
</body>

</html>
